package top.cyuw.subjectsystem.vo;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class ResponseVo<T> extends BaseVo {

    private final Integer code;

    private final String msg;

    private final T data;

    public static ResponseVo<Boolean> judge(boolean success) {
        return success ? success() : failure();
    }

    public static <T> ResponseVo<T> success() {
        return newResponse(200, "操作成功", null);
    }

    public static <T> ResponseVo<T> success(T data) {
        return newResponse(200, "操作成功", data);
    }

    public static <T> ResponseVo<T> success(String msg, T data) {
        return newResponse(200, msg, data);
    }

    public static <T> ResponseVo<T> failure() {
        return newResponse(400, "操作失败", null);
    }

    public static <T> ResponseVo<T> failure(T data) {
        return newResponse(400, "操作失败", data);
    }

    public static <T> ResponseVo<T> failure(String msg, T data) {
        return newResponse(400, msg, data);
    }

    public static <T> ResponseVo<T> disallow() {
        return newResponse(400, "权限不足", null);
    }

    public static <T> ResponseVo<T> disallow(T data) {
        return newResponse(400, "权限不足", data);
    }

    public static <T> ResponseVo<T> newResponse(Integer code, String msg, T data) {
        return new ResponseVo<>(code, msg, data);
    }
}
